﻿var searchData=[{name:"Like",code:"0"},{name:"=",code:"1"},{name:"<>",code:"2"},{name:">",code:"3"},{name:"<",code:"4"},{name:">=",code:"5"},{name:"<=",code:"6"},{name:"in",code:"7"},{name:"not in",code:"8"},{name:"is null",code:"9"},{name:"is not null",code:"10"}];
var searchfieldData;
//初始化入口
$(function() {
    $('#dlgresult-search').dialog('close');
    $('#dlgresult-addData').dialog('close'); 
});

//查询
function btnresult_search(){
    var selected=$('#treeload').tree('getSelected');
    if(selected){
        requestAjax('Controller.aspx?controller=GeneralController&method=GetFieldNames&titleId=' + selected.id, {}, function(data) {
                            $('#searchfield1').combobox('loadData',data);
                             $('#searchfield2').combobox('loadData',data);
                              $('#searchfield3').combobox('loadData',data);
                               $('#searchfield4').combobox('loadData',data);
                                $('#searchfield5').combobox('loadData',data);
                        });
        $('#search1').combobox('loadData',searchData);
         $('#search2').combobox('loadData',searchData);
          $('#search3').combobox('loadData',searchData);
           $('#search4').combobox('loadData',searchData);
            $('#search5').combobox('loadData',searchData);
        $('#dlgresult-search').dialog('open');
    }
}

//查询确定
function dlgresult_searchOk(){
    var selected=$('#treeload').tree('getSelected');
    if(selected){
        var param1="&field1="+ $('#searchfield1').combobox('getValue')+"&search1="+$('#search1').combobox('getText')+"&value1="+$('#searchvalue1').val();
        var param2="&field2="+ $('#searchfield2').combobox('getValue')+"&search2="+$('#search2').combobox('getText')+"&value2="+$('#searchvalue2').val();
        var param3="&field3="+ $('#searchfield3').combobox('getValue')+"&search3="+$('#search3').combobox('getText')+"&value3="+$('#searchvalue3').val();
        var param4="&field4="+ $('#searchfield4').combobox('getValue')+"&search4="+$('#search4').combobox('getText')+"&value4="+$('#searchvalue4').val();
        var param5="&field5="+ $('#searchfield5').combobox('getValue')+"&search5="+$('#search5').combobox('getText')+"&value5="+$('#searchvalue5').val();
        $('#resultGird').datagrid('options').url='Controller.aspx?controller=GeneralController&method=QryResultData&titleId='+selected.id+param1+param2+param3+param4+param5;
        $('#resultGird').datagrid('reload');
        $('#dlgresult-search').dialog('close');
    }
}
//添加数据
function btnresult_addData(){
    var selected=$('#treeload').tree('getSelected');
    if(selected){
        requestAjax('Controller.aspx?controller=GeneralController&method=LoadPageAddData&titleId=' + selected.id, {}, function(data) {
                $('#addDataDiv').empty();
                $('#addDataDiv').load("GeneralData_AddData.aspx",{},function(){
                    $.parser.parse($('#addDataDiv'));
                 });
            });
        $('#dlgresult-addData').dialog('open'); 
    }
}

//添加数据确定
function dlgresult_addDataOk(){
    var selected=$('#treeload').tree('getSelected');
    if(selected){
        FormSubmit($('#formresultaddData'), 'Controller.aspx?controller=GeneralController&method=AddResultData&titleId='+selected.id, function() {
                        $('#dlgresult-addData').dialog('close'); 
                        $('#resultGird').datagrid('reload');
                    });
                }
}

//编辑数据
function btnresult_editData(){

        var selectgrid=$('#resultGird').datagrid('getSelections');
        if(selectgrid.length>0){
            requestAjax('Controller.aspx?controller=GeneralController&method=LoadPageAddData&titleId=' + titleId, {}, function(data) {
                    $('#addDataDiv').empty();
                    $('#addDataDiv').load("GeneralData_AddData.aspx",{},function(){
                        $.parser.parse($('#addDataDiv'));
                        $('#formresultaddData').form('load',selectgrid[0]);
                     });
                });
            $('#dlgresult-addData').dialog('open');
        }
}

//删除数据
function btnresult_delData(){
        var selectgrid=$('#resultGird').datagrid('getSelections');
        if(selectgrid.length>0){
            var ids = [];
            for(var i=0;i<selectgrid.length;i++){
                for(var m in selectgrid[i]){
                    if(m==resulstDataKeyName)
				        ids.push(selectgrid[i][m]);
				}
			}

            $.messager.confirm('询问', '是否要删除此记录？', function(r){
				if (r){
					 requestAjax('Controller.aspx?controller=GeneralController&method=DeleteResultData', { TitleId: titleId,ResultKeyName:resulstDataKeyName, ResultId:ids.join(',')}, function(data) {
                            $('#resultGird').datagrid('reload');
                        });
				}
			});
		}
}
